{% extends "base_generic.html" %}

{% block content %}
<div class="card detail-card">
  <h1 class="detail-title">{{ book.title }}</h1>

  <div class="detail-row">
    <span class="detail-label">Author:</span>
    <a href="{{ book.author.get_absolute_url }}">{{ book.author }}</a>
  </div>

  <div class="detail-row">
    <span class="detail-label">Summary:</span>
    <div class="book-summary">
      {{ book.summary|linebreaks }}
    </div>
  </div>

  <div class="detail-row">
    <span class="detail-label">ISBN:</span>
    <span class="isbn-value">{{ book.isbn|default:"Not available" }}</span>
  </div>

  <div class="detail-row">
    <span class="detail-label">Language:</span>
    {{ book.language }}
  </div>

  <div class="detail-row">
    <span class="detail-label">Genre:</span>
    {{ book.genre.all|join:", " }}
  </div>

  <h4 class="mt-4">Copies</h4>

  {% for copy in book.bookinstance_set.all %}
    <div class="copy-item">
      <p class="{% if copy.status == 'a' %}status-available{% elif copy.status == 'd' %}status-reserved{% else %}status-maintenance{% endif %}">
        {{ copy.get_status_display }}
      </p>
      {% if copy.status != 'a' %}
        <p><span class="detail-label">Due to be returned:</span> {{copy.due_back}}</p>
      {% endif %}
      <p><span class="detail-label">Imprint:</span> {{copy.imprint}}</p>
      <p><span class="detail-label">Id:</span> <a href="{{ copy.get_absolute_url }}">{{copy.id}}</a></p>
    </div>
  {% empty %}
    <p>The library has no copies of this book.</p>
  {% endfor %}
</div>
{% endblock %}


{% block sidebar %}
  {{ block.super }}

  {% if perms.catalog.change_book or perms.catalog.delete_book %}
  <hr>
  <ul class="sidebar-nav">
    {% if perms.catalog.change_book %}
      <li><a href="{% url 'book-update' book.id %}">Update Book</a></li>
    {% endif %}
    {% if not book.bookinstance_set.all and perms.catalog.delete_book %}
      <li><a href="{% url 'book-delete' book.id %}">Delete Book</a></li>
    {% endif %}
    </ul>
  {% endif %}

{% endblock %}
